package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import com.laowang.common.utils.DateUtils;
import com.laowang.common.utils.MobileCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.TbReceiveAddressMapper;
import com.laowang.project.system.domain.TbReceiveAddress;
import com.laowang.project.system.service.TbReceiveAddressService;

import javax.validation.constraints.NotBlank;

/**
 * 收件地址Service业务层处理
 *
 * @author laowang
 * @date 2022-12-21
 */
@Service
public class TbReceiveAddressServiceImpl implements TbReceiveAddressService {
    @Autowired
    private TbReceiveAddressMapper tbReceiveAddressMapper;

    /**
     * 查询收件地址
     *
     * @param id 收件地址ID
     * @return 收件地址
     */
    @Override
    public TbReceiveAddress selectTbReceiveAddressById(Long id) {
        return tbReceiveAddressMapper.selectTbReceiveAddressById(id);
    }

    /**
     * 查询收件地址列表
     *
     * @param tbReceiveAddress 收件地址
     * @return 收件地址
     */
    @Override
    public List<TbReceiveAddress> selectTbReceiveAddressList(TbReceiveAddress tbReceiveAddress) {
        return tbReceiveAddressMapper.selectTbReceiveAddressList(tbReceiveAddress);
    }

    /**
     * 新增收件地址
     *
     * @param tbReceiveAddress 收件地址
     * @return 结果
     */
    @Override
    public int insertTbReceiveAddress(TbReceiveAddress tbReceiveAddress) {
        String phone = tbReceiveAddress.getPhone();
        if (!MobileCheck.isMobile(phone)) {
            throw new CustomException("手机格式有误", 400);
        }
        tbReceiveAddress.setCreateTime(DateUtils.getNowDate());
        return tbReceiveAddressMapper.insertTbReceiveAddress(tbReceiveAddress);
    }

    /**
     * 修改收件地址
     *
     * @param tbReceiveAddress 收件地址
     * @return 结果
     */
    @Override
    public int updateTbReceiveAddress(TbReceiveAddress tbReceiveAddress) {
        return tbReceiveAddressMapper.updateTbReceiveAddress(tbReceiveAddress);
    }

    /**
     * 批量删除收件地址
     *
     * @param ids 需要删除的收件地址ID
     * @return 结果
     */
    @Override
    public int deleteTbReceiveAddressByIds(Long[] ids) {
        return tbReceiveAddressMapper.deleteTbReceiveAddressByIds(ids);
    }

    /**
     * 删除收件地址信息
     *
     * @param id 收件地址ID
     * @return 结果
     */
    @Override
    public int deleteTbReceiveAddressById(Long id) {
        return tbReceiveAddressMapper.deleteTbReceiveAddressById(id);
    }
}
